<?php
/**
 * 
 * SearchAction.class.php (前台搜索功能)
 *
 * @package      	szflame
 * @author          
 * @copyright     	
 * @license         
 * @version        	szflame企业网站管理系统 v2012.12.12 2011-03-01 198616.com $
 */
if(!defined("szflame")) exit("Access Denied");
class SearchAction extends BaseAction
{

	function _initialize()
    {	
		parent::_initialize();
    }

    public function index()
    {
		//var_dump($_REQUEST);
		//$_REQUEST['id'] = $catid =  intval($_REQUEST['id']);
		$_REQUEST['id'] = $catid =  3;
		$p= max(intval($_REQUEST[C('VAR_PAGE')]),1);
		$_REQUEST['keyword'] = $keyword = trim($_REQUEST['keyword']);
		$_REQUEST['module'] = $module =  get_safe_replace($_REQUEST['module']);
		$module =  $module ? $module  : 'Article';
		$this->assign($_REQUEST);
		$this->assign('bcid',0);
		$where['status'] = 1;			
		if(APP_LANG){
			$lang = LANG_NAME;
			$langid= LANG_ID;
			$where['lang'] = LANG_ID;
			$this->assign('lang',$lang);
			$this->assign('langid',$langid);
		}
		if($catid){
			$cat = $this->categorys[$catid];		
			$bcid = explode(",",$cat['arrparentid']); 
			$bcid = $bcid[1]; 
			if($bcid == '') $bcid=intval($catid);
			if(empty($module))$module=$cat['module'];	
			unset($cat['id']);
			$this->assign($cat);
			$cat['id']=$catid;
			$this->assign('catid',$catid);
			$this->assign('bcid',$bcid);
			
			$where['catid'] = array("in",$cat['arrchildid']);
		}
		$seo_title = $cat['title'] ? $cat['title'] : $cat['catname'];
		$this->assign ('seo_title',$keyword.' '.$seo_title);
		$this->assign ('seo_keywords',$keyword.$cat['keywords']);
		$this->assign ('seo_description',$keyword.$cat['description']);
		

		//var_dump($keyword);
		if($keyword){
			$map['title'] = array("like","%".$keyword."%");
			$map['jianjie'] = array("like","%".$keyword."%");
			$map['_logic'] = 'or';
			$where['_complex'] = $map;
		}
		
		$this->dao= M($module);
		$this->dao= M('Article');
		$count = $this->dao->where($where)->count();
		//echo $this->dao->getLastSql();
		if($count){
			import ( "@.ORG.Page" );
			$listRows =  !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
			$page = new Page ( $count, $listRows );
			$_REQUEST['p'] = '{$page}';
			$page->urlrule =  URL('Home-Search/index',$_REQUEST);
			$pages = $page->show();
			//$field =  $this->module[$cat['moduleid']]['listfields'];
			//$field =  $field ? $field : 'id,catid,userid,url,username,title,title_style,keywords,description,thumb,createtime,hits';
			$list = $this->dao->field('*')->where($where)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
			$this->assign('pages',$pages);
			//echo $this->dao->getLastSql();
			$this->assign('list',$list);
		}
		
		$this->display();

    } 
}
?>